/// 用户历史记录项实体
/// 
/// 用于表示用户在某个日期的活动或评论历史记录
class UserHistoryItemEntity {
  final int id;
  final String type; // '活动' 或 '评论'
  final String title; // 标题
  final String content; // 内容描述
  final String? location; // 地点（可选）
  final String? createTime; // 创建时间
  final String? publishTime; // 发布时间
  final List<String>? images; // 图片列表
  final String? publisherNickname; // 发布者昵称
  final String? publisherAvatar; // 发布者头像
  final List<String>? category; // 分类标签
  
  // 活动特有字段
  final int? currentParticipants; // 当前参与人数
  final int? maxParticipants; // 最大参与人数
  
  // 评论特有字段
  final int? likeCount; // 点赞数
  final int? commentCount; // 评论数

  UserHistoryItemEntity({
    required this.id,
    required this.type,
    required this.title,
    required this.content,
    this.location,
    this.createTime,
    this.publishTime,
    this.images,
    this.publisherNickname,
    this.publisherAvatar,
    this.category,
    this.currentParticipants,
    this.maxParticipants,
    this.likeCount,
    this.commentCount,
  });

  /// 从JSON创建实体
  factory UserHistoryItemEntity.fromJson(Map<String, dynamic> json) {
    return UserHistoryItemEntity(
      id: json['id'] as int,
      type: json['type']?.toString() ?? '活动',
      title: json['title']?.toString() ?? '无标题',
      content: json['content']?.toString() ?? '',
      location: json['location']?.toString(),
      createTime: json['createTime']?.toString(),
      publishTime: json['publishTime']?.toString(),
      images: (json['images'] as List<dynamic>?)
          ?.map((e) => e.toString())
          .toList(),
      publisherNickname: json['publisherNickname']?.toString(),
      publisherAvatar: json['publisherAvatar']?.toString(),
      category: (json['category'] as List<dynamic>?)
          ?.map((e) => e.toString())
          .toList(),
      currentParticipants: json['currentParticipants'] as int?,
      maxParticipants: json['maxParticipants'] as int?,
      likeCount: json['likeCount'] as int?,
      commentCount: json['commentCount'] as int?,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'type': type,
      'title': title,
      'content': content,
      if (location != null) 'location': location,
      if (createTime != null) 'createTime': createTime,
      if (publishTime != null) 'publishTime': publishTime,
      if (images != null) 'images': images,
      if (publisherNickname != null) 'publisherNickname': publisherNickname,
      if (publisherAvatar != null) 'publisherAvatar': publisherAvatar,
      if (category != null) 'category': category,
      if (currentParticipants != null) 'currentParticipants': currentParticipants,
      if (maxParticipants != null) 'maxParticipants': maxParticipants,
      if (likeCount != null) 'likeCount': likeCount,
      if (commentCount != null) 'commentCount': commentCount,
    };
  }

  /// 是否是活动类型
  bool get isActivity => type == '活动' || type == 'activity';

  /// 是否是评论类型
  bool get isComment => type == '评论' || type == 'comment';

  /// 获取类型显示名称
  String get typeDisplayName {
    if (isActivity) return '活动';
    if (isComment) return '评论';
    return type;
  }

  /// 获取类型颜色（用于UI显示）
  String get typeColorHex {
    if (isActivity) return '#D84545'; // 红色
    if (isComment) return '#2196F3'; // 蓝色
    return '#D84545'; // 默认红色
  }
}

